package com.itboye.lottery.activity;

import android.text.Html;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.itboye.lottery.base.BaseActivity;
import com.itboye.lottery.R;
import com.itboye.lottery.alert.ByAlert;
import com.itboye.lottery.bean.ZhuiHaoDetailBean;
import com.itboye.lottery.presenter.UserPresenter;
import com.itboye.lottery.retrofit.ResponseCallback;

import org.jetbrains.annotations.NotNull;

public class ZhuiHaoDetailActivity extends BaseActivity implements ResponseCallback {

    LinearLayout li_zhuihao_detail_1;
    String id;
    UserPresenter userPresenter = new UserPresenter(this);
    TableRow tr_zhuihao_detail_1;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_zhui_hao_detail;
    }

    @Override
    protected void initData() {
        id = getIntent().getStringExtra("id");
        userPresenter.getZhuiHaoDetail(id);
    }

    @Override
    public void onClick(View view) {

    }

    @Override
    public void success(@NotNull Object o, @NotNull String requestSuccessType) {
        ZhuiHaoDetailBean zhuiHaoDetailBean = (ZhuiHaoDetailBean) o;
        ((TextView) li_zhuihao_detail_1.getChildAt(0)).setText(Html.fromHtml("彩&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;种:&nbsp;<font color='black'>" + zhuiHaoDetailBean.getAlias_name() + "</font>"));
        ((TextView) li_zhuihao_detail_1.getChildAt(1)).setText(Html.fromHtml("追号类型:&nbsp;<font color='black'>" + (zhuiHaoDetailBean.getIs_rand() == 0 ? "固定追号" : "随机追号") + "</font>"));
        ((TextView) li_zhuihao_detail_1.getChildAt(2)).setText(Html.fromHtml("追号金额:&nbsp;<font color='black'>" + zhuiHaoDetailBean.getAmount() + "元</font>"));
        ((TextView) li_zhuihao_detail_1.getChildAt(3)).setText(Html.fromHtml("追号期数:&nbsp;<font color='black'>" + (zhuiHaoDetailBean.getPush_number()) + "期</font>"));

        ((TextView) tr_zhuihao_detail_1.getChildAt(0)).setText(zhuiHaoDetailBean.getPush_number()+"");
        ((TextView) tr_zhuihao_detail_1.getChildAt(1)).setText(zhuiHaoDetailBean.getBet().getPlaytype());//投注方案
        ((TextView) tr_zhuihao_detail_1.getChildAt(2)).setText(zhuiHaoDetailBean.getAmount()+"元");
        ((TextView) tr_zhuihao_detail_1.getChildAt(3)).setText(zhuiHaoDetailBean.getAdd_time());
        ((TextView) tr_zhuihao_detail_1.getChildAt(4)).setText(getResult(zhuiHaoDetailBean.getIs_prize()));//投注结果
    }

    private String getResult(int isPrize) {
        switch (isPrize) {
            case 0:
                return "未开奖";
            case 1:
                return "已中奖";
            case 2:
                return "未中奖";
        }
        return "";
    }

    @Override
    public void fail(int code, @NotNull Object msg, @NotNull String requestErrorType) {
        ByAlert.alert(msg);
    }
}
